from pyecharts import options as opts
from pyecharts.charts import Map
from DataAnalyze import CountryNum
from translate import Translator

# 实例话翻译类：从中文翻译为英文
translator = Translator(from_lang="Chinese", to_lang="English")
data = CountryNum()
# 对每一个数据进行翻译
for idx, cou in enumerate(data[0]):
    if cou == "美国":
        data[0][idx] = "United States"
        continue
    if cou == "英国":
        data[0][idx] = "United Kingdom"
        continue
    if cou in ["中国大陆", "中国香港", "中国台湾", "1964(中国大陆)"]:
        cou = "中国"
    target = translator.translate(f'{cou}')
    data[0][idx] = target
    if idx % 5 == 0:
        print(target)


map_table = (
    Map()
    .add("上映地区", [list(z) for z in zip(data[0], data[1])], "world")
    .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
    .set_global_opts(
        title_opts=opts.TitleOpts(title="Map-世界地图"),
        visualmap_opts=opts.VisualMapOpts(max_=145),
    )
    .render("../SourceChart/Map.html")
)
